package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.search.vos.SearchArticleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(value = "app文章管理API",tags = "app文章管理API")
@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {
    @Autowired
    private ApArticleService apArticleService;

    @ApiOperation(value = "保存app文章",notes = "保存 app_article信息,ap_article_config信息,ap_article_content信息")
    @PostMapping("/save")
    public ResponseResult addArticle(@RequestBody ArticleDto articleDto) {
        return apArticleService.addArticle(articleDto);
    }

    @ApiOperation("根据ID查询文章搜索VO")
    @GetMapping("{id}")
    public ResponseResult<SearchArticleVo> findArticle(@PathVariable Long id) {
        SearchArticleVo searchArticleVo = null;
        ApArticle article = apArticleService.getById(id);
        if(article!=null){
            searchArticleVo = new SearchArticleVo();
            BeanUtils.copyProperties(article,searchArticleVo);
        }
        return ResponseResult.okResult(searchArticleVo);
    }
}
